import time
import datetime
from datetime import datetime, timedelta


def get_current_date():
    return datetime.now().date()


def get_current_time():
    return datetime.now().time()


def get_common_date():
    return datetime.now().strftime("%Y-%m-%d %H:%M:%S")


def get_date_from_string(date_string, date_format='%Y-%m-%d'):
    return datetime.strptime(date_string, date_format).date()


def get_time_from_string(time_string, date_format='%H:%M:%S'):
    return datetime.strptime(time_string, date_format).time()


def date_to_string(date, date_format='%Y-%m-%d'):
    return date.strftime(date_format)


# 按照格式获取时间   %Y-%m-%d %H:%M:%S

def get_date(date_format):
    t = time.localtime()
    current_time = time.strftime(date_format, t)
    return current_time


def get_last_by_day(count):
    # 获取今天的日期
    today = datetime.today()
    # 计算去年的今天
    last_year = today - timedelta(days=count)
    return date_to_string(last_year)


if __name__ == '__main__':
    # today = get_last_by_day(365)
    print(get_common_date())
